/*
 *   Clovis
 *   Copyright (C) 2008 SFWOL
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "CInteger.h"

namespace clovis {

	namespace core {


        CInteger::CInteger(std::string name , int value) : ClovisVariable(name){
            this->value = value;
        }


        CInteger::CInteger(int value) : ClovisVariable(){

            this->value = value;

        }

        CInteger::CInteger() : ClovisVariable(){

            this->value = 0;

        }

        std::string CInteger::getClass(){

        	return "CInteger";

        }

  		void CInteger::operator = (int value){

			this->value = value;

		}

		void CInteger::operator = (CInteger value){

			this->value = value.get();

		}

		CInteger CInteger::operator + (CInteger value){

			return CInteger(this->value + value.get());

		}

		void CInteger::operator ++ (){

			++this->value;

		}

		CInteger CInteger::operator ++ (int value){

			return this->value++;

		}

		CInteger CInteger::operator - (CInteger value){

			return CInteger(this->value - value.get());

		}

		void CInteger::operator -- (){

			--this->value;

		}

		CInteger CInteger::operator -- (int value){

			return this->value--;

		}

		CInteger CInteger::operator * (CInteger value){

			return CInteger(this->value * value.get());

		}

		CInteger CInteger::operator / (CInteger value){

		    try {

                int temp = value.get();

                if ( temp == 0 )
                    throw temp;
                else
                    return CInteger(this->value / temp);

		    } catch(int i) {

                io::Log::logOn(io::FATAL_ERROR,"Division by zero");
                exit(-1);
		    }

		}

		bool CInteger::operator > (CInteger value){

			if(this->value > value.toInt())
				return true;
			else
				return false;

		}

		bool CInteger::operator >= (CInteger value){

			if(this->value >= value.toInt())
				return true;
			else
				return false;

		}

		bool CInteger::operator < (CInteger value){

			if(this->value < value.toInt())
				return true;
			else
				return false;

		}

		bool CInteger::operator <= (CInteger value){

			if(this->value <= value.toInt())
				return true;
			else
				return false;

		}

		CInteger CInteger::operator + (int value){

			return CInteger(this->value + value);

		}

		CInteger CInteger::operator - (int value){

			return CInteger(this->value - value);

		}

		CInteger CInteger::operator * (int value){

			return CInteger(this->value * value);

		}

		CInteger CInteger::operator / (int value){

			try {

                int temp = value;

                if ( temp == 0 )
                    throw temp;
                else
                    return CInteger(this->value / temp);

		    } catch(int i) {

                io::Log::logOn(io::FATAL_ERROR , "Division by zero");
                exit (-1);
		    }

		}

		bool CInteger::operator > (int value){

			if(this->value > value)
				return true;
			else
				return false;

		}

		bool CInteger::operator >= (int value){

			if(this->value >= value)
				return true;
			else
				return false;

		}

		bool CInteger::operator < (int value){

			if(this->value < value)
				return true;
			else
				return false;

		}

		bool CInteger::operator <= (int value){

			if(this->value <= value)
				return true;
			else
				return false;

		}

		bool CInteger::operator != (int value){

			if(this->value != value)
				return true;
			else
				return false;

		}

		bool CInteger::operator != (CInteger value){

			if(this->value != value.toInt())
				return true;
			else
				return false;

		}

        int CInteger::get(){

			return this->value;

		}

		int CInteger::toInt(){

			return this->value;

		}

		std::string CInteger::toString(){

			std::stringstream ss;
			std::string str;

			ss << this->value;
			ss >> str;

			return str;

		}

		CString CInteger::toCString(){

			CString tmp = this->toString();
			return tmp;

		}

		CFloat CInteger::toCFloat(){

			CFloat temp = (float)this->value;
			return temp;

		}

    };

};

